package com.xbongbong.saas.model;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.IModel;
import com.xbongbong.pro.businessdata.pojo.dto.FormatExplainDTO;
import com.xbongbong.pro.domain.entity.UpdateDataEntity;
import com.xbongbong.pro.formdata.pojo.dto.SaasAnalysisDataDTO;
import com.xbongbong.saas.domain.entity.InstockProductEntity;
import com.xbongbong.saas.domain.entity.ProductStockInfoEntity;
import com.xbongbong.saas.domain.entity.UpdateStockDataEntity;
import com.xbongbong.saas.domain.entity.ext.InstockEntityExt;
import com.xbongbong.saas.domain.entity.ext.ProductEntityExt;
import com.xbongbong.saas.enums.UpdateDataTypeEnum;
import org.elasticsearch.action.support.WriteRequest;

import java.util.List;
import java.util.Map;

/**
 * 入库单
 * @author 吴峰
 * @version v1.0
 * @date 2019/2/18 15:08
 * @since v1.0
 */
public interface InstockModel extends IModel<InstockEntityExt> {
    /**
     * 查询单个实体
     * @param key 数据id
     * @param corpid 公司id
     * @return 实体
     */
    InstockEntityExt getByKey(Long key, String corpid);

    /**
     * 根据data里某个条件搜索
     *
     * @param attr   data里属性
     * @param value  data里属性的值
     * @param param 参数
     */
    Integer getCountByOneCondition(String attr, Object value, Map<String,Object> param);

    /**
     * 根据条件获取入库单ID
     * @param param 参数集合
     * @return List<Long> 入库单参数集合
     */
    List<Long> findIds(Map<String, Object> param);
    /**
     * 获取符合查询条件的记录
     *
     * @param param 查询条件
     * @return 符合查询条件的记录
     */
    @Override
    List<InstockEntityExt> findEntitys(Map<String, Object> param);
    /**
     * 保存
     * @param instock 数据
     *
     */
    Integer save(InstockEntityExt instock) throws XbbException;

    /**
     * 去掉特定的入库单
     * @param instockIdList 入库单产品集合
     * @param instockIds 入库单产品集合
     */
    void removeInstock(List<Long> instockIdList,List<Long> instockIds);

    /**
     * 批量删除出库单
     * @param idList
     * @param corpid
     * @return
     * @throws XbbException
     */
    Integer deleteBatch(List<Long> idList, String corpid) throws XbbException;

    Integer deleteBatchImmediately(List<Long> idList, String corpid) throws XbbException;

    /**
     * 删除出库单
     * @param id
     * @param corpid
     * @return
     * @throws XbbException
     */
    Integer deleteByKey(Long id,String corpid) throws XbbException;

    /**
     * 批量编辑
     * @author 吴峰
     * @date 2019/3/20 14:37
     * @param updateDataList
     * @param corpid 公司id
     * @return java.lang.Integer
     * @throws XbbException 业务异常
     */
    Integer updateBatch(List<UpdateDataEntity> updateDataList, String corpid) throws XbbException;
    /**
     * 批量编辑
     * @author 吴峰
     * @date 2019/3/20 14:37
     * @param updateDataList
     * @param corpid 公司id
     * @return java.lang.Integer
     * @throws XbbException 业务异常
     */
    Integer updateBatchDataByType(List<UpdateStockDataEntity> updateDataList, String corpid) throws XbbException;

    /**
     * 批量更新团队
     *
     * @param dataIdList
     * @param corpid
     * @param userId
     * @throws
     * @author long.rao
     * @date 2020-04-10 10:53
     */
    Integer batchUpdateOwner(List<Long> dataIdList, String corpid, String userId, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    List<String>  getCorpidList();

    /**
     * 批量编辑
     * @author 吴峰
     * @date 2020/6/15 11:17
     * @param updateList
     * @param corpid 公司id
     * @return java.lang.Integer
     * @throws XbbException 业务异常
     */
    Integer updateBatch(List<UpdateDataEntity> updateList, String corpid, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;


    /**
     * 根据供应商ID和业务类型获取符合查询条件的记录
     *
     * @param param 查询条件
     * @return 符合查询条件的记录
     */
    List<InstockEntityExt> getBySupplierId(Map<String, Object> param);

    List findEntitysWithoutSub(Map<String, Object> param);

    /**
     * 编辑时格式化解释
     *
     * @param formatExplainDTO 入参
     * @throws XbbException 异常
     */
    void formatUpdateExplain(FormatExplainDTO formatExplainDTO) throws XbbException;

    /**
     * 新建时格式化解释
     *
     * @param formatExplainDTO 入参
     * @throws XbbException 异常
     */
    Boolean formatAddExplain(FormatExplainDTO formatExplainDTO) throws XbbException;

    /**
     * 编辑时将获取数据格式化
     *
     * @param formDataUpdateGetDTO saas编辑数据
     * @param result               要返回的jsonobject
     * @throws XbbException 业务异常
     * @author feng.zheng
     * @date 2019/1/22 15:28
     */
    void formatData(SaasAnalysisDataDTO formDataUpdateGetDTO, JSONObject result) throws XbbException;

    void getProductList(String corpid, List<InstockProductEntity> instockProductList, List<ProductStockInfoEntity> productStockInfoList, JSONArray productArray, Map<Long, ProductEntityExt> productMap) throws XbbException;

    void formatNewProductList(String corpid, List<InstockProductEntity> instockProductEntityList, JSONArray productArray, Map<Long, ProductEntityExt> productMap) throws XbbException;

    void formatProduct4Show2(Long dataId, String corpid, JSONObject data, Boolean forProcess, Integer operate, UpdateDataTypeEnum updateDataTypeEnum) throws XbbException;

    /**
     * 解析
     * @param entity
     * @return
     */
    JSONObject formatSingleProduct(InstockProductEntity entity);

    List<PaasFormDataEntityExt> findInstockList(String corpid, Integer type, Long refId, List<Integer> flowStatusIn, List<String> fieldList) throws XbbException;
}
